package com.zzm.validate.web;

import javax.activation.UnsupportedDataTypeException;
import javax.servlet.http.HttpServletRequest;

/**
 * 用于HTTP Servlet环境下
 * 将一个 HttpServletRequest 对象转换成一个Map以用于参数验证
 */
public class HttpServletRequestMapAdapter extends MapAdapter {

	private HttpServletRequest request;
	
	public HttpServletRequestMapAdapter(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	@Override
	public String get(Object key) {
		if(!(key instanceof String)) {
			throw new RuntimeException(new UnsupportedDataTypeException(key.getClass().getName()));
		}
		return this.request.getParameter(key.toString());
	}

	
	
}
